<!DOCTYPE html>
<html>
<head>
    <th:block th:include="include :: headermain('互助保障系统V3')"/>
    <script src="/plugin/jquery/jquery.min.js"></script>
    <script src="/plugin/jquery/jquery.plugin.js"></script>
    <script src="/plugin/vue/vue.min.js"></script>
    <script src="/plugin/layui/layui.all.js"></script>
    <script src="/unit/resource/js/script.js"></script>
    <title>业务办理-申领业务</title>
</head>
<body>
<div class="page">
    <!-- 头部信息 -->
    <th:block th:include="include :: top"/>
    <div class="center">
        <div class="page-content page-wrap">
            <!-- 左侧导航 -->
            <th:block th:include="include :: left"/>
            <div class="page-wrap-container">

                <div class="claim-apply">

                    <div class="page-step">
                        <span class="complete">选择计划</span>
                        <i class="fa fa-arrow-circle-right complete"></i>
                        <span class="current">上传资料</span>
                        <i class="fa fa-arrow-circle-right current"></i>
                        <span>提交审核</span>
                    </div>

                    <c:if test="${hzClaim.back == 1}">
                        <div class="page-tips error" style="margin:0 0 30px 0;">退回原因：${hzClaim.backcontent}</div>
                    </c:if>
                    <form class="page-form">
                        <input type="hidden" name="id" value="${hzClaim.id}" />
                        <div class="page-form-header">入会基本信息</div>
                        <table class="page-table" style="margin-bottom:20px;">
                            <tr>
                                <th>姓名</th>
                                <td>${hzClaim.person.name}</td>
                                <th>证件号码</th>
                                <td>${hzClaim.person.idCard}</td>
                            </tr>
                            <tr>
                                <th>入会计划</th>
                                <td>${hzClaim.insuranceName}</td>
                                <th>入会份数</th>
                                <td>${policyInsurance.unitqty}份</td>
                            </tr>
                            <tr>
                                <th>观察期</th>
                                <td>${policyInsurance.freeday}天</td>
                                <th>申领类别</th>
                                <td>${hzClaim.categoryName}</td>
                            </tr>
                            <tr>
                                <th>有效保障期</th>
                                <td>${startTime} 至 ${endTime}</td>
                                <th>申领期限</th>
                                <td>${claimTerm}前</td>
                            </tr>
                        </table>

                        <div class="page-form-header">经办人信息</div>
                        <div class="page-form-item">
                            <div class="page-form-label">联系人：</div>
                            <div class="page-form-input">
                                <input type="text" style="width:80px" name="contactname" value="${hzClaim.contactname}" />
                                <span style="color:red">*</span>
                            </div>
                        </div>
                        <div class="page-form-item">
                            <div class="page-form-label">联系手机：</div>
                            <div class="page-form-input">
                                <input type="text" style="width:120px" name="contactmobile" value="${hzClaim.contactmobile}" />
                                <span style="color:red">*</span>
                            </div>
                        </div>
                        <div class="page-form-item">
                            <div class="page-form-label">联系邮箱：</div>
                            <div class="page-form-input">
                                <input type="text" style="width:180px" name="contactemail" value="${hzClaim.contactemail}" />
                            </div>
                        </div>
                        <div class="page-form-item">
                            <div class="page-form-label">联系电话：</div>
                            <div class="page-form-input">
                                <input type="text" style="width:120px" name="contactphone" value="${hzClaim.contactphone}" />
                            </div>
                        </div>
                        <div class="page-form-header">职工会员信息</div>
                        <div class="page-form-item">
                            <div class="page-form-label">职工手机：</div>
                            <div class="page-form-input">
                                <input type="text" style="width:120px" name="personmobile" value="${hzClaim.personmobile}" />
                                <span style="color:red">*</span>
                            </div>
                        </div>
                        <div class="page-form-item">
                            <div class="page-form-label">职工邮箱：</div>
                            <div class="page-form-input">
                                <input type="text" style="width:180px" name="personemail" value="${hzClaim.personemail}" />
                            </div>
                        </div>

                        <input type="hidden" name="personnotice" value="1" />
                        <%-- <div class="page-form-item">
                        <div class="page-form-label">接收通知：</div>
                        <div class="page-form-input">
                            <select class="page-form-select" name="personnotice" val="${hzClaim.personnotice}">
                                <option value="1">接收</option>
                                <option value="0">不接收</option>
                            </select>
                            <div class="page-form-placeholder">申请职工本人是否接收办理情况通知</div>
                        </div>
                    </div> --%>

                        <div class="page-form-item">
                            <div class="page-form-label">收款银行卡照片：</div>
                            <!-- 医保卡、银行卡证件照id：6 -->
                            <div class="page-form-input">
                                <div class="claim-apply-file-list claim-apply-file6">
                                    <!-- 存放上传的文件 -->
                                    <c:forEach items="${changeBankProveFile.claimProveFiles}" var="claimProveFile">
                                        <div class="claim-apply-file-item">
                                            <img id="bankImg" data-id="${claimProveFile.id}" src="${claimProveFile.fileurl}" />
                                            <a class="claim-apply-file-btn layui-btn layui-btn-sm" target="_blank" href="/hzclaim/hzClaimFront/viewImages?fileurl=${claimProveFile.fileurl}">查看</a>
                                            <a class="claim-apply-file-btn layui-btn layui-btn-primary layui-btn-sm" onclick="delFile('${claimProveFile.id}', this)">删除</a>
                                        </div>
                                    </c:forEach>
                                </div>
                                <a class="claim-apply-file-upload-btn" data-id="6" title="点此上传资料">
                                    <i class="fa fa-plus"></i>
                                    <span>上传文件</span>
                                </a>
                                <!-- <span style="color:#FF0000;margin-left:10px;">*</span> -->
                                <div class="page-form-placeholder">请上传收款银行卡照片,不能是信用卡、理财卡、银行存折等，必须是正常使用的储蓄卡。<span style="color:red;">正本</span>复印件，建议使用扫描仪扫描为jpg图片上传。如无扫描仪，可直接使用手机拍照上传，手机拍照必须保证内容清晰可见<span id="lose"></span></div>
                            </div>
                            <input type="file" id="claim_apply_file_input" style="filter:alpha(opacity=0);opacity:0;width: 0;height: 0;" accept="image/png, image/jpeg, image/jpg" />
                        </div>

                        <div class="page-form-item">
                            <div class="page-form-label">银行卡号：</div>
                            <div class="page-form-input">
                                <input type="text" style="width:200px" id="bankCard" name="bankcard" value="${hzClaim.bankcard}" />
                                <span style="color:red">*</span>
                            </div>
                        </div>
                        <div class="page-form-item" id='bankNameLast'>
                            <div class="page-form-label">银行名称：</div>
                            <div class="page-form-input">
                                <input type="text" style="width:200px" id="bankname" name="bankname" value="${hzClaim.bankname}" />
                                <span style="color:red">*</span>
                            </div>
                        </div>
                        <c:if test="${not empty hzClaim.bankNo}">
                            <div class='page-form-item' id='bankNo'>
                                <div class='page-form-label'>行号：</div>
                                <div class='page-form-input'>
                                    <input type='text' style='width:120px' name='bankno' value='${hzClaim.bankNo}' />
                                </div>
                            </div>
                        </c:if>

                        <div class="page-form-item">
                            <div class="page-form-label">疾病种类：</div>
                            <div class="page-form-input">
                                <select class="page-form-select" name="diseaseType" val="${hzClaim.diseaseType}">
                                    <c:forEach items="${hzConfDiseaseTypes}" var="hzConfDiseaseType">
                                        <option value="${hzConfDiseaseType.id}">${hzConfDiseaseType.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>

                        <div class="page-form-item">
                            <div class="page-form-label">诊疗方式：</div>
                            <div class="page-form-input">
                                <select class="page-form-select" name="inpatientClinic" val="${hzClaim.inpatientClinic}">
                                    <option value="1">住院</option><option value="2">门诊</option>
                                </select>
                            </div>
                        </div>

                        <div style="color:red; padding:10px 0;border-bottom:1px dashed #ddd; margin-bottom:35px;"> 请注意！ * 号为必填项，填写的手机、邮箱等用于接收互助金办理情况通知，请务必填写真实有效！ </div>
                        <div class="page-form-header">住院资料</div>
                        <table class="page-table page-table-list page-form-table claim-apply-hospital-table">
                            <tr>
                                <th>医院名称</th>
                                <th>医院等级</th>
                                <th>是否本地</th>
                                <th>入院时间</th>
                                <th>出院时间</th>
                                <th></th>
                            </tr>
                            <c:if test="${empty claimHospitals}">
                                <tr>
                                    <td>
                                        <input type="hidden" id="hospitalId" name="hospitalId" value="" />
                                        <input type="text" id="hospitalName" name="hospitalName" class="page-form-search hospitalName" value="" autocomplete="off" />
                                    </td>
                                    <td>
                                        <select class="page-form-select" id="hospitalGrade" name="hospitalGrade" val="">
                                            <option value="1">一级</option><option value="2">二级</option><option value="3">三级</option>
                                        </select>
                                    </td>
                                    <td>
                                        <select class="page-form-select" id="hospitalLocal" name="hospitalLocal" val="">
                                            <option value="1">本地医院</option>
                                            <option value="0">外地医院</option>
                                        </select>
                                    </td>
                                    <td><input type="text" class="page-form-date" id="startTime" name="startTime" value="" placeholder="" autocomplete="off"/></td>
                                    <td><input type="text" class="page-form-date" id="endTime" name="endTime" placeholder="" value="" autocomplete="off"/></td>
                                    <td><a class="layui-btn layui-btn-sm remove-hospital">删除</a></td>
                                </tr>
                            </c:if>
                            <c:if test="${not empty claimHospitals}">
                                <c:forEach items="${claimHospitals}" var="claimHospital">
                                    <tr>
                                        <td>
                                            <input type="hidden" id="hospitalId" name="hospitalId" value="${claimHospital.hzConfHospital.id}" />
                                            <input type="text" id="hospitalName" name="hospitalName" class="page-form-search hospitalName" value="${claimHospital.hzConfHospital.name}" autocomplete="off" />
                                        </td>
                                        <td>
                                            <select class="page-form-select" id="hospitalGrade" name="hospitalGrade" val="${claimHospital.hzConfHospital.grade}">
                                                <option value="1">一级</option><option value="2">二级</option><option value="3">三级</option>
                                            </select>
                                        </td>
                                        <td>
                                            <select class="page-form-select" id="hospitalLocal" name="hospitalLocal" val="${claimHospital.hzConfHospital.islocal}">
                                                <option value="1">本地医院</option>
                                                <option value="0">外地医院</option>
                                            </select>
                                        </td>
                                        <td><input type="text" class="page-form-date" id="startTime" name="startTime" value="${claimHospital.startDate}" placeholder="" autocomplete="off"/></td>
                                        <td><input type="text" class="page-form-date" id="endTime" name="endTime" placeholder="" value="${claimHospital.endDate}" autocomplete="off"/></td>
                                        <td><a class="layui-btn layui-btn-sm remove-hospital">删除</a></td>
                                    </tr>
                                </c:forEach>
                            </c:if>
                        </table>
                        <a class="layui-btn claim-apply-btn-hospital-add" style="margin-bottom:35px; margin-top:10px;">添加医院</a>
                        <div class="page-form-header">职工医疗互助申领资料</div>
                        <c:forEach items="${claimFieldInfos}" var="claimFieldInfo">
                            <div class="page-form-item">
                                <div class="page-form-label">${claimFieldInfo.fieldName}：</div>
                                <div class="page-form-input">
                                    <c:choose>
                                        <c:when test="${claimFieldInfo.fieldTypes == 3}">
                                            <textarea name="${claimFieldInfo.claimFieldId}" style="width:500px; height:200px;">${claimFieldInfo.valueString}</textarea>
                                        </c:when>
                                        <c:otherwise>
                                            <c:if test="${empty claimFieldInfo.valueEecimal}">
                                                <input type="text" style="width:100px" name="${claimFieldInfo.claimFieldId}" value="0" onfocus="if (value =='0'){value =''}" onblur="if (value ==''){value='0'}" />
                                            </c:if>
                                            <c:if test="${not empty claimFieldInfo.valueEecimal}">
                                                <input type="text" style="width:100px" name="${claimFieldInfo.claimFieldId}" value="${claimFieldInfo.valueEecimal}" />
                                            </c:if>
                                        </c:otherwise>
                                    </c:choose>
                                    <c:if test="${claimFieldInfo.isMust == 1}">
                                        <span style="color:red">*</span>
                                    </c:if>
                                    <div class="page-form-placeholder">${claimFieldInfo.fieldRemarks}</div>
                                </div>
                            </div>
                        </c:forEach>

                        <div class="page-form-header">职工医疗互助证明文件</div>
                        <c:forEach items="${claimFileInfos}" var="claimFileInfo">
                            <div class="claim-apply-file">
                                <h2>${claimFileInfo.fileName}</h2>
                                <div class="claim-apply-file-list claim-apply-file${claimFileInfo.fileId}">
                                    <c:forEach items="${claimFileInfo.claimProveFiles}" var="claimProveFile">
                                        <div class="claim-apply-file-item">
                                            <img src="${claimProveFile.fileurl}" />
                                            <a class="claim-apply-file-btn layui-btn layui-btn-sm" target="_blank" href="/hzclaim/hzClaimFront/viewImages?fileurl=${claimProveFile.fileurl}">查看</a>
                                            <a class="claim-apply-file-btn layui-btn layui-btn-primary layui-btn-sm" onclick="delFile('${claimProveFile.id}', this)">删除</a>
                                        </div>
                                    </c:forEach>
                                </div>
                                <a class="claim-apply-file-upload-btn" data-id="${claimFileInfo.fileId}" title="点此上传资料">
                                    <i class="fa fa-plus"></i>
                                    <span>上传文件</span>
                                </a>
                            </div>
                        </c:forEach>
                        <!-- 转院证明 -->
                        <c:if test="${not empty changeHospitalProveFile}">
                            <div class="claim-apply-file" id="change-hospital-prove-file" style="display: block">
                        </c:if>
                        <c:if test="${empty changeHospitalProveFile}">
                            <c:if test="${not empty claimHospitals and fn:length(claimHospitals) > 1}">
                                <div class="claim-apply-file" id="change-hospital-prove-file" style="display: block">
                            </c:if>
                            <c:if test="${empty claimHospitals or fn:length(claimHospitals) <= 1}">
                                <div class="claim-apply-file" id="change-hospital-prove-file" style="display: none">
                            </c:if>
                        </c:if>
                        <h2>转院证明</h2>
                        <!-- 转院证明id：7 -->
                        <div class="claim-apply-file-list claim-apply-file7">
                            <c:if test="${not empty changeHospitalProveFile}">
                                <c:forEach items="${changeHospitalProveFile.claimProveFiles}" var="claimProveFile">
                                    <div class="claim-apply-file-item">
                                        <img src="${claimProveFile.fileurl}" />
                                        <a class="claim-apply-file-btn layui-btn layui-btn-sm" target="_blank" href="/hzclaim/hzClaimFront/viewImages?fileurl=${claimProveFile.fileurl}">查看</a>
                                        <a class="claim-apply-file-btn layui-btn layui-btn-primary layui-btn-sm" onclick="delFile('${claimProveFile.id}', this)">删除</a>
                                    </div>
                                </c:forEach>
                            </c:if>
                        </div>
                        <a class="claim-apply-file-upload-btn" data-id="7" title="点此上传资料">
                            <i class="fa fa-plus"></i>
                            <span>上传文件</span>
                        </a>
                </div>

                <input type="file" id="claim_apply_file_input" style="filter:alpha(opacity=0);opacity:0;width: 0;height: 0;" accept="image/png, image/jpeg, image/jpg" />

                <div class="page-form-item">
                    <div class="page-form-label">特别备注：</div>
                    <div class="page-form-input">
                        <textarea name="remarks">${hzClaim.remarks}</textarea>
                        <div class="page-form-placeholder">向所属机构特别说明的内容</div>
                    </div>
                </div>
                <div class="page-form-item" style="border-top:1px dashed #ddd; width:100%; padding-top:15px; ">
                    <div class="page-form-label"></div>
                    <div class="page-form-input">
                        <a class="layui-btn layui-btn-primary save-btn">保存资料</a>
                        <a class="layui-btn next-btn">提交审核</a>
                        <a class="layui-btn layui-btn-danger del-btn">删除申请</a>
                    </div>
                </div>
                </form>
            </div>

        </div>
    </div>
</div>
<!-- 底部信息 -->
<th:block th:include="include :: footer"/>
</div>

<script type="text/javascript">

    /* 查询银行信息方法 */
    function getBankNames(bankCard){
        var idx = layer.load(0);
        $.soon.ajax({
            url: "/hzclaim/hzClaimFront/getBankNo?bankCard=" + bankCard,
            success: function (data) {
                if(data.success){
                    var bankName = data.body.hzConfBank.name;
                    var bankNo = data.body.hzConfBank.pcbBankno;
                    $('#bankname').val(bankName);
                    getBankNo(bankName, bankNo);
                    layer.close(idx);
                }else {
                    layer.close(idx);
                    $("#bankNo").remove();
                    $('#bankname').val("");
                    // 银行卡号检验不通过
                    layer.prompt({
                        formType: 0,
                        closeBtn: 0, // 关闭按钮样式
                        value: '',
                        area:['450px', 'auto'],
                        title: '请再次确认银行卡号。',
                        btn: ['确定','取消'], //按钮，
                        btn2: function(index, elem){
                            $('#bankCard').val("");
                        },
                        btnAlign: 'c'
                    }, function (value,index) {
                        if(value != bankCard){
                            layer.msg('两次输入卡号不一致', {time:2000})
                        }if(value == bankCard){
                            layer.close(index);
                        }
                    });
                }
            }
        });
    }

    /* 根据银行名称判断是否为农信社,输入行号 */
    function getBankNo(bankName, bankNo){
        $("#bankNo").remove();
        var tag = "农";
        var tag2 = "信";
        if(bankName.indexOf(tag)!=-1 && bankName.indexOf(tag2)!=-1){
            $("#bankNameLast").after($("<div class='page-form-item' id='bankNo'><div class='page-form-label'>行号：</div><div class='page-form-input'><input type='text' style='width:120px' name='bankno' value='"+ bankNo +"' /></div></div>"))
        }
    }

    /* 输入银行名称后调用方法,鼠标离开输入框 */
    $("#bankname").change(function() {
        var bankName = $(this).val();
        if(bankName != null && bankName != ""){
            getBankNo(bankName, "");
        }
    });

    /* 输入银行卡号后调用方法,鼠标离开输入框 */
    $("#bankCard").change(function() {
        var bankCard = $(this).val();
        if(bankCard != null && bankCard != ""){
            getBankNames(bankCard);
        }
    });


    // 保存资料
    $(".save-btn").click(function () {
        if($(".hospitalName").length <= 1){ // 判断是否转院
            $('#change-hospital-prove-file').attr("style","display:none;");//隐藏div
            var fileId = $('#change-hospital-prove-file').find(".claim-apply-file-upload-btn").attr("data-id");
            // 删除转院证明本地文件以及数据库关联信息
            var idx = layer.load(0);
            $.soon.ajax({
                url: "/hzclaim/hzClaimFront/delChangeHospitalProveFile?fileid="+ fileId +"&claimid=${hzClaim.id}",
                success: function (data) {
                    if(data.success){
                        $('#change-hospital-prove-file').find(".claim-apply-file7 div").remove();
                    }
                }
            });
        }

        var data = [];
        $(".hospitalName").each(function () {
            var hospitalId = $(this).parents("tr").find("#hospitalId").val(); // 医院id
            var hospitalName = $(this).parents("tr").find("#hospitalName").val(); // 医院名称
            var hospitalGrade = $(this).parents("tr").find("#hospitalGrade").val(); // 医院等级
            var hospitalLocal = $(this).parents("tr").find("#hospitalLocal").val(); // 是否本地
            var startTime = $(this).parents("tr").find("#startTime").val(); // 入院时间
            var endTime = $(this).parents("tr").find("#endTime").val(); // 出院时间
            data.push({
                hospitalId: hospitalId,
                hospitalName: hospitalName,
                hospitalGrade: hospitalGrade,
                hospitalLocal: hospitalLocal,
                startTime: startTime,
                endTime: endTime
            });
        });
        // 行号
        var bankNo = $("input[name='bankno']").val();
        if(bankNo == null || bankNo == "" || bankNo == "undefined"){
            bankNo = "";
        }
        $.soon.ajax({
            url: "/hzclaim/hzClaimFront/saveClaimApply",
            data: $(".page-form").serialize()+"&bankNo="+bankNo+"&"+$.param({submitType:'0',hospitalInfo: JSON.stringify(data)}),
            success: function (data) {
                layer.close(idx);
                if (data.success) {
                    layer.msg("保存成功");
                    setTimeout(function () {
                        window.location.reload();
                    }, 1000);
                } else {
                    layer.msg(data.msg);
                }
            }
        });
    });

    // 提交审核
    $(".next-btn").click(function () {
        var tips = 0;
        var duration = 0;
        var submitfn = function(){
            if($(".hospitalName").length <= 1){ // 判断是否转院
                $('#change-hospital-prove-file').attr("style","display:none;");//隐藏div
                var fileId = $('#change-hospital-prove-file').find(".claim-apply-file-upload-btn").attr("data-id");
                // 删除转院证明本地文件以及数据库关联信息
                var idx = layer.load(0);
                $.soon.ajax({
                    url: "/hzclaim/hzClaimFront/delChangeHospitalProveFile?fileid="+ fileId +"&claimid=${hzClaim.id}",
                    success: function (data) {
                        if(data.success){
                            $('#change-hospital-prove-file').find(".claim-apply-file7 div").remove();
                        }
                    }
                });
            }

            var data = [];
            $(".hospitalName").each(function () {
                var hospitalId = $(this).parents("tr").find("#hospitalId").val(); // 医院id
                var hospitalName = $(this).parents("tr").find("#hospitalName").val(); // 医院名称
                var hospitalGrade = $(this).parents("tr").find("#hospitalGrade").val(); // 医院等级
                var hospitalLocal = $(this).parents("tr").find("#hospitalLocal").val(); // 是否本地
                var startTime = $(this).parents("tr").find("#startTime").val(); // 入院时间
                var endTime = $(this).parents("tr").find("#endTime").val(); // 出院时间
                data.push({
                    hospitalId: hospitalId,
                    hospitalName: hospitalName,
                    hospitalGrade: hospitalGrade,
                    hospitalLocal: hospitalLocal,
                    startTime: startTime,
                    endTime: endTime
                });
            });
            // 行号
            var bankNo = $("input[name='bankno']").val();
            if(bankNo == null || bankNo == "" || bankNo == "undefined"){
                bankNo = "";
            }
            $.soon.ajax({
                url: "/hzclaim/hzClaimFront/saveClaimApply",
                data: $(".page-form").serialize()+"&bankNo="+bankNo+"&"+$.param({submitType:'1',hospitalInfo: JSON.stringify(data)}),
                success: function (data) {
                    layer.close(idx);
                    if (data.success) {
                        layer.msg("提交成功");
                        window.location.href = "/hzclaim/hzClaimFront/unitClaimDetails?id=${hzClaim.id}";
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
        }
        if (tips == 1) {
            var idx = layer.open({
                title:'办理须知',
                btn:false,
                area:['500px','auto'],
                content: '<div class="page-tips-submit"><p></p><a class="layui-btn layui-btn-disabled">请仔细阅读办理须知</a></div>'
            });
            var interval = setInterval(function(){
                $("#layui-layer" + idx + " .layui-btn ").html("请仔细阅读办理须知（"+duration+"秒）");
                if (duration <= 0) {
                    $("#layui-layer" + idx + " .layui-btn").removeClass("layui-btn-disabled");
                    $("#layui-layer" + idx + " .layui-btn").html("我已阅读，立即提交");
                    $("#layui-layer" + idx + " .layui-btn").click(submitfn);
                    clearInterval(interval);
                }else {
                    duration--;
                }
            },1000);
        }else {
            layer.confirm('确实要提交审核吗？', {
                btn: ['提交', '取消']
            }, function () {
                submitfn();
            });
        }
    });

    // 上传按钮
    $(".claim-apply-file-upload-btn").click(function () {
        var fileid = $(this).attr("data-id");
        $("#claim_apply_file_input").attr("data-id", fileid).trigger("click");
    });

    // 上传证明文件资料
    $("#claim_apply_file_input").change(function () {
        var fileid = $(this).attr("data-id");
        var form = new FormData();
        var File = $("#claim_apply_file_input")[0].files[0]
        form.append("fileid", fileid);
        form.append("claimid", '${hzClaim.id}');
        form.append("file", File);
        var size = File.size / 1024;
        if (size > 5 * 1024) {
            layer.msg("图片不能超过5M，请重新选择!");
            return false;
        }
        if (!File.type.match(/image.*/)) {
            layer.msg('请选择正确的图片!')
            return false;
        }
        var idx = layer.load(0);
        $.ajax({
            type: "post",
            url: "/hzclaim/hzClaimFront/claimApplyFileUpload",
            data: form,
            dataType: "json",
            processData: false,
            contentType: false,
            success: function (data) {
                if (data.success) {
                    if(fileid == '6'){
                        // 删除原文件
                        var delFileId = $("#bankImg").attr("data-id");
                        if(delFileId != null && delFileId != ""){
                            $.soon.ajax({
                                url: "/hzclaim/hzClaimFront/delClaimApplyFile?id=" + delFileId,
                                success: function (data) {

                                }
                            });
                            $(".claim-apply-file" + fileid).empty();
                        }
                    }
                    var html = '';
                    html += '<div class="claim-apply-file-item">';
                    if(fileid == '6'){
                        html += '	<img id="bankImg" data-id="'+ data.body.hzClaimProveFile.id +'" src="' + data.body.hzClaimProveFile.fileurl + '" />';
                    }else{
                        html += '	<img src="' + data.body.hzClaimProveFile.fileurl + '" />';
                    }
                    html += '	<a class="claim-apply-file-btn layui-btn layui-btn-sm" target="_blank" href="/hzclaim/hzClaimFront/viewImages?fileurl='+ data.body.hzClaimProveFile.fileurl +'">查看</a>';
                    html += '	<a class="claim-apply-file-btn layui-btn layui-btn-primary layui-btn-sm" onclick="delFile(\'' + data.body.hzClaimProveFile.id + '\',this)">删除</a>';
                    html += '</div>';
                    $(".claim-apply-file" + fileid).append(html);
                    if(fileid == '6'){
                        // 银行卡号
                        var bankCard = data.body.bankCard;
                        if(bankCard != null && bankCard != '' && bankCard != '无'){
                            $("#bankCard").val(bankCard);
                            getBankNames(bankCard);
                        }else{
                            $("#bankNo").remove();
                            $("#bankname").val("");
                            $("#bankCard").val("");
                            layer.msg(data.msg);
                        }
                    }
                    layer.close(idx);
                } else {
                    layer.close(idx);
                    layer.msg(data.msg);
                }
            }, error: function () {
                layer.close(idx);
                layer.msg("数据提交失败");
            }
        });
    });

    // 删除证明文件资料
    function delFile(id, tag) {
        layer.confirm('确实要删除资料吗？', {
            btn: ['删除', '取消']
        }, function () {
            $.soon.ajax({
                url: "/hzclaim/hzClaimFront/delClaimApplyFile?id=" + id,
                success: function (data) {
                    layer.msg("删除成功");
                    $(tag).parent().remove();
                }
            });
        });
    }

    $(".page-form-select").each(function () {
        if ($(this).attr("val")) {
            $(this).val($(this).attr("val"));
        }
    });

    /* 添加医院  */
    $(".claim-apply-btn-hospital-add").click(function () {
        var html = '<tr>' +
            '<td>' +
            '<input type="hidden" id="hospitalId" name="hospitalId" value="" />' +
            '<input type="text" id="hospitalName" name="hospitalName" class="page-form-search hospitalName" autocomplete="off"/>' +
            '</td>' +
            '<td>' +
            '<select id="hospitalGrade" name="hospitalGrade">' +
            '<option value="1">一级</option><option value="2">二级</option><option value="3">三级</option>' +
            '</select>' +
            '</td>' +
            '<td>' +
            '<select id="hospitalLocal" name="hospitalLocal">' +
            '<option value="1">本地医院</option>' +
            '<option value="0">外地医院</option>' +
            '</select>' +
            '</td>' +
            '<td><input type="text" class="page-form-date" id="startTime" name="startTime" placeholder="" autocomplete="off"/></td>' +
            '<td><input type="text" class="page-form-date" id="endTime" name="endTime" placeholder="" autocomplete="off"/></td>' +
            '<td><a class="layui-btn layui-btn-sm remove-hospital">删除</a></td>' +
            '</tr>';
        $(".claim-apply-hospital-table").append(html);

        // 入院出院时间
        $(".claim-apply-hospital-table tr:last-child .page-form-date").each(function () {
            layui.laydate.render({
                elem: this
            });
        });

        // 获取医院信息
        $(".page-form-search").change(function() {
            var hospitalName = $(this).val();
            var tag = this;
            if(hospitalName != null && hospitalName != ""){
                var idx = layer.load(0);
                $.soon.ajax({
                    url: "/hzclaim/hzClaimFront/getHospitalByName?hospitalName=" + hospitalName,
                    success: function (data) {
                        layer.close(idx);
                        if(data.success){
                            $(tag).parents("tr").find("input[name='hospitalId']").val(data.body.confHospital.id);
                            $(tag).parents("tr").find("select[name='hospitalGrade']").val(data.body.confHospital.grade);
                            $(tag).parents("tr").find("select[name='hospitalLocal']").val(data.body.confHospital.islocal);
                        }
                    }
                });
            }
        });

        // 获取医院数量
        if($(".hospitalName").length > 1){
            $('#change-hospital-prove-file').attr("style","display:block;");//显示div
        }else {
            $('#change-hospital-prove-file').attr("style","display:none;");//隐藏div
            var fileId = $('#change-hospital-prove-file').find(".claim-apply-file-upload-btn").attr("data-id");
            // 删除转院证明本地文件以及数据库关联信息
            var idx = layer.load(0);
            $.soon.ajax({
                url: "/hzclaim/hzClaimFront/delChangeHospitalProveFile?fileid="+ fileId +"&claimid=${hzClaim.id}",
                success: function (data) {
                    layer.close(idx);
                    if(data.success){
                        $('#change-hospital-prove-file').find(".claim-apply-file7 div").remove();
                    }
                }
            });
        }

        // 删除医院
        $(".remove-hospital").click(function () {
            $(this).parents('tr').remove();
            if($(".hospitalName").length > 1){
                $('#change-hospital-prove-file').attr("style","display:block;");//显示div
            }else {
                $('#change-hospital-prove-file').attr("style","display:none;");//隐藏div
                var fileId = $('#change-hospital-prove-file').find(".claim-apply-file-upload-btn").attr("data-id");
                // 删除转院证明本地文件以及数据库关联信息
                var idx = layer.load(0);
                $.soon.ajax({
                    url: "/hzclaim/hzClaimFront/delChangeHospitalProveFile?fileid="+ fileId +"&claimid=${hzClaim.id}",
                    success: function (data) {
                        layer.close(idx);
                        if(data.success){
                            $('#change-hospital-prove-file').find(".claim-apply-file7 div").remove();
                        }
                    }
                });
            }
        })
    });

    // 删除医院
    $(".remove-hospital").click(function () {
        $(this).parents('tr').remove();
        if($(".hospitalName").length > 1){
            $('#change-hospital-prove-file').attr("style","display:block;");//显示div
        }else {
            $('#change-hospital-prove-file').attr("style","display:none;");//隐藏div
            var fileId = $('#change-hospital-prove-file').find(".claim-apply-file-upload-btn").attr("data-id");
            // 删除转院证明本地文件以及数据库关联信息
            var idx = layer.load(0);
            $.soon.ajax({
                url: "/hzclaim/hzClaimFront/delChangeHospitalProveFile?fileid="+ fileId +"&claimid=${hzClaim.id}",
                success: function (data) {
                    layer.close(idx);
                    if(data.success){
                        $('#change-hospital-prove-file').find(".claim-apply-file7 div").remove();
                    }
                }
            });
        }
    })

    // 入院出院时间
    $(".claim-apply-hospital-table tr:last-child .page-form-date").each(function () {
        layui.laydate.render({
            elem: this
        });
    });

    // 获取医院信息
    $(".page-form-search").change(function() {
        var hospitalName = $(this).val();
        if(hospitalName != null && hospitalName != ""){
            var tag = this;
            var idx = layer.load(0);
            $.soon.ajax({
                url: "/hzclaim/hzClaimFront/getHospitalByName?hospitalName=" + hospitalName,
                success: function (data) {
                    layer.close(idx);
                    if(data.success){
                        $(tag).parents("tr").find("input[name='hospitalId']").val(data.body.confHospital.id);
                        $(tag).parents("tr").find("select[name='hospitalGrade']").val(data.body.confHospital.grade);
                        $(tag).parents("tr").find("select[name='hospitalLocal']").val(data.body.confHospital.islocal);
                    }
                }
            });
        }
    });

    $(".del-btn").click(function () {

        layer.confirm('确实要删除本次申请吗？', {
            btn: ['删除', '取消']
        }, function () {
            var idx = layer.load(0);
            $.soon.ajax({
                url: "/hzclaim/hzClaimFront/applyDeleteClaim?id=${hzClaim.id}",
                success: function (data) {
                    layer.msg("删除成功");
                    setTimeout(function () {
                        window.location.href = "/hzclaim/hzClaimFront/unitClaimData?pageNo=1&pageSize=10&unitid=8d8484b417e74bd0afd3c1bf84969391";
                    }, 3000);
                }
            });
        });


    });

    /* 查看图片 */
    function openImg(fileurl){
        layer.open({
            title: "图片查看",
            area: ['60%','90%'],
            content:"<div style='text-align:center;width: 95%;height: 100%;display: table-cell;vertical-align: middle;'><img style='width: 1050px;height: 700px;' src='"+ fileurl +"'></div>",
        });

    }

</script>

</body>
</html>
